import threading
import time
import uuid
from collections import namedtuple

_dict = [
    ("idle",),
    ("normal",),
]

status = [namedtuple("Key", ["id", "state"])(i + 1, item[0]) for i, item in enumerate(_dict)]

state = status[0]

Do = namedtuple("Do", ["id", "name", "condition", "before", "update", "complete"])

do_list = []
do = None
if __name__ == '__main__':
    do_list += [
        Do(uuid.UUID.hex,
           "test1",
           lambda: state == status[0],
           lambda: (print("enter 111")),
           lambda *y: (print(1111)),
           None),
        Do(uuid.UUID.hex,
           "test2",
           lambda: state == status[1],
           lambda: (print("enter 222")),
           lambda *y: (print(2222)),
           None),
    ]


    def change_state():
        global state
        while True:
            time.sleep(2)
            state = status[1]


    threading.Thread(target=change_state, daemon=True).start()

    while True:
        if do is not None:
            do.update()
        for _do in do_list:
            if do is not _do:
                if _do.condition():
                    if do is not None and do.complete:
                        do.complete()
                    do = _do
                    do.before()
